<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');


$aTTD = array(1=>'Bilancio UE');
$aTTD[2] = 'Bilancio riclassificato';
$aTTD[3] = 'Rendiconto finanziario';
$aTTD[11] = $acRec['indici1'];
$aTTD[12] = $acRec['indici2'];
$aTTD[13] = $acRec['indici3'];

if (reqVar('azione') == 'elimina') {
	$msgPag .= confElim();
} 
$sqlSel = "SELECT * ".
		" FROM rgl_set_dati ".
		" WHERE id_set_dati = ".intval(reqVar('sd'));
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("tabDatiVis - var. id. '".reqVar('sd')."' mancante o errato");
}
$aTTD = array(1=>'Bilancio UE');
$aTTD[2] = 'Bilancio riclassificato';
$aTTD[3] = 'Rendiconto finanziario';
$aTTD[11] = $acRec['indici1'];
$aTTD[12] = $acRec['indici2'];
$aTTD[13] = $acRec['indici3'];

$_REQUEST = array_merge($acRec,$_REQUEST);
$idSetDati = $acRec['id_set_dati'];

$cmdL = "";
$cmdL .= "<a class='cmd1' href='tabDatiPdf.php?sd=".reqVar('sd')."&ttd=".reqVar('ttd')."&$sXSNQS' target='_blank'>PDF</a>";
$cmdL .= "&nbsp;&nbsp;&nbsp;";
$cmdL .= "<a class='cmd1' href='tabDatiExp.php?sd=".reqVar('sd')."&ttd=".reqVar('ttd')."&$sXSNQS' target='_blank'>export csv</a>";
$cmdL .= "&nbsp;&nbsp;&nbsp;";

$sCmdPagR = '';
if (true) {
	$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	$sCmdPagR .= "<a class='cmd1' href='datoIns.php?sd=".reqVar('sd')."&ttd=".reqVar('ttd')."&$sXSNQS' >nuovo dato</a>";
}
$sCmdPagR .= cmdTorna(); 

testaHtml('Gestione modelli',$msgPag, 'modl');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif(20);?>
   <tr>
      <td class="cmd1" align="left" colspan='10'><?=$cmdL?></td>
      <td class="cmd1" align="right" colspan='10'><?=$sCmdPagR?></td>
   </tr>
   <tr>
      <td class="cmd1" colspan='20' align='right'>
<?
foreach($aTTD as $kX => $sX) {
	if ($kX==reqVar('ttd') || $sX == '') {
		continue;
	}
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		."<a href='tabDatiVis.php?ttd=$kX&sd=".reqVarInt('sd')."&xsn=".XSN."' class='cmd1'>$sX</a>\n";
}
?>
		</td>
   </tr>
   <tr>
      <td class="tit1" colspan='20' align='center'>Definizione tabella dati</td>
   </tr>
   <tr>
      <td class="lab1" colspan='4' align='left'>Set dati</td>
      <td class="txt1" colspan='2' align='left'>
			<?=$acRec['cod_set_dati'];?>
		</td>
      <td class="txt1" colspan='14' align='left'>
			<?=$acRec['descr'];?>
		</td>
	</tr>
   <tr>
      <td class="lab1" align="center" colspan='20'>
			<b><?=$aTTD[reqVar('ttd')]?></b>
		</td>
   </tr>
<?
$aGeDati = getGerarcTabdati(reqVar('sd'),reqVar('ttd'));
//dbg_($aGeDati);
foreach($aGeDati as $codX => $aX) {
	echoDato($idSetDati,$codX,$aX,0);
}
?>
</table>
   <tr>
      <td class="cmd1" align="right" colspan='20'><?=$sCmdPagR?></td>
   </tr>
<?
codaHtml();
exit();
function echoDato($idSetDati,$codX,$aX,$liv) {
	if (reqVar('ttd')==1) {
		$colspanDes = 14;
	} else {
		$colspanDes = 16;
	}
	$aCSez = array(''=>'-- non sezione --');
	$aCSez['spatt'] = 'Stato patrimoniale - Attivo';
	$aCSez['sppas'] = 'Stato patrimoniale - Passivo';
	$aCSez['cecon'] = 'Conto economico';
	$aCSez['altro'] = 'Altri dati';
	$aCSez['calco'] = 'Dati calcolati';
	
	if ($aX['attr']['cod_sez']!='') {
		echo "<tr><td class='txt2' align='center' colspan='$colspanDes'><b>".$aCSez[$aX['attr']['cod_sez']]."</b></td>"
		."<td class='txt2' colspan='1' align='center'>seq.</td>\n"
		."<td class='txt2' colspan='1' align='center'>tipo</td>\n"
		."<td class='txt2' colspan='1' align='center'>".((reqVar('ttd')==1)?'quad.':'calc.')."</td>\n"
		."<td class='txt2' colspan='1' align='center'>scr.</td>\n";
		if ($colspanDes == 14) {
			 echo "<td class='txt2' colspan='1' align='center'>S/P</td>\n"
				."<td class='txt2' colspan='1' align='center'>var.</td>\n";
		}
		echo "</tr>\n";
	}
	echo "<tr>\n<td class='txt1' colspan='$colspanDes'>".str_repeat("&nbsp;",$liv*8)
		."<a href='datoVis.php?sd=$idSetDati&cd=$codX&xsn=".XSN."' class='txt1'>$codX</a> - ".$aX['attr']['descr']."</td>\n"
		."<td class='txt1' colspan='1' align='center'>".$aX['attr']['seq']."</td>\n"
		."<td class='txt1' colspan='1' align='center'>".$aX['attr']['tipo_valore']."</td>\n"
		."<td class='txt1' colspan='1' align='center'>".$aX['attr']['flag_quad_calc']."</td>\n"
		."<td class='txt1' colspan='1' align='center'>".((empty($aX['attr']['script']))?'':'S')."</td>\n";
	if ($colspanDes == 14) {
		 echo "<td class='txt1' colspan='1' align='center'>".$aX['attr']['situaz_progr']."</td>\n"
			."<td class='txt1' colspan='1' align='right'>".$aX['attr']['segnala_variaz']."%</td>\n";
	}
	echo "</tr>\n";
	foreach($aX['figli'] as $codY => $aY)  {
		echoDato($idSetDati,$codY,$aY,$liv+1);
	}
}
